package com.yantong.controller.api;

import com.yantong.annotation.Auth;
import com.yantong.controller.BaseController;
import com.yantong.pojo.BalanceLog;
import com.yantong.pojo.WdListParams;
import com.yantong.pojo.Withdrawals;
import com.yantong.result.ResultVo;
import com.yantong.service.BalanceService;
import com.yantong.service.WithdrawalsService;
import com.yantong.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author: juzi
 * @date: 2021/10/25
 * @time: 16:12
 */
@ApiIgnore
@Controller
@RequestMapping("/wxapi/balance")
public class ApiBlanceController extends BaseController {

    @Autowired
    private WithdrawalsService withdrawalsService;
    @Autowired
    private BalanceService balanceService;


    /**
     * 提现
     */
    @RequestMapping("/pick")
    @ResponseBody
    @Auth(arg = 0)
    public ResultVo drawMoney(Long memberId, Double money, String isgys, String bankcard) {
        int result = balanceService.cash(memberId, money, null, isgys, bankcard);
        ResultVo resultVo = new ResultVo();
        resultVo.put("success", true);
        resultVo.put("data", result);
        return resultVo;
    }

    /**
     * 体现记录
     */
    @RequestMapping("/pick/record")
    @ResponseBody
    @Auth
    public ResultVo drawMoneyRecord(WdListParams params, int offset, int limit) {
        PageUtils<Withdrawals> records = withdrawalsService.listWithdrawals(params, offset, limit);
        ResultVo resultVo = new ResultVo();
        resultVo.put("success", true);
        resultVo.put("data", records);
        return resultVo;
    }

    /**
     * 余额列表/明细
     */
    @RequestMapping("/list")
    @ResponseBody
    @Auth
    public ResultVo getBalanceList(BalanceLog balanceLog, Integer offset, Integer limit) {
        if (null == offset) {
            offset = 0;
        }
        if (null == limit) {
            limit = 10;
        }
        PageUtils<BalanceLog> logs = balanceService.listBalanceLogs(balanceLog, offset, limit);
        ResultVo resultVo = new ResultVo();
        resultVo.put("success", true);
        resultVo.put("data", logs);
        return resultVo;
    }

    /**
     * 得到账户供应商流水
     *
     * @param mid    用户Id
     * @param offset 分页
     * @param limit  每页显示数
     * @return
     */
    @RequestMapping("/getsupllyBalanceLog")
    @ResponseBody
    @Auth
    public ResultVo getsupllyBalanceLog(Long mid, Long flowtype, int offset, int limit) {
        PageUtils<BalanceLog> list = balanceService.getsupllyBalanceLog(mid, flowtype, offset, limit);
        ResultVo resultVo = new ResultVo();
        resultVo.put("success", true);
        resultVo.put("data", list);
        return resultVo;
    }


}
